function FigPointLabel(p, str, loc, varargin)
%FigPointLabel - 向figure上的点添加文本说明
% 
% Syntex: FigPointLabel(p, str, loc[, 'Color', color, 'FontSize', fontsize]) 
%
% Params: p 点在figure上的坐标
%        str 待标注的文本
%        loc 文本相对点的位置, 可选值包括：
%            northwest,     north,   northeast,
%                 west,       p           east,
%            southwest,     south,   southeast, 
%        [Color] 字体的颜色
%        [FontSize] 字体大小
% 
% Return: None

%% 输入参数处理
% 将元胞数组转换为结构体
inputParams = mdng.cellToStruct(varargin);
% 默认参数的结构体
defaultParams = struct( ...
    'Color', [0.8, 0.52, 0.98], ...
    'FontSize',  14 ...
    );
% 修改默认设置
defaultParams = mdng.structAssign(defaultParams, inputParams);


%% 在坐标轴上的指定某点添加标注
ptx = p(1); pty = p(2);
switch loc
    case 'north'
        label_pos = [ptx-0.05, pty-0.01, 0.1, 0.1];
        hAlign = 'center';
        vAlign = 'bottom';
    case 'south'
        label_pos = [ptx-0.05, pty-0.1, 0.1, 0.1];
        hAlign = 'center';
        vAlign = 'top';
    case 'east'
        label_pos = [ptx, pty-0.05-0.008, 0.1, 0.1];
        hAlign = 'left';
        vAlign = 'middle';
    case 'west'
        label_pos = [ptx-0.1, pty-0.05-0.008, 0.1, 0.1];
        hAlign = 'right';
        vAlign = 'middle';
    case 'northwest'
        label_pos = [ptx-0.1, pty-0.01, 0.1, 0.1];
        hAlign = 'right';
        vAlign = 'bottom';
    case 'northeast'
        label_pos = [ptx, pty-0.01, 0.1, 0.1];
        hAlign = 'left';
        vAlign = 'bottom';
    case 'southwest'
        label_pos = [ptx-0.1, pty-0.1, 0.1, 0.1];
        hAlign = 'right';
        vAlign = 'top';
    case 'southeast'
        label_pos = [ptx, pty-0.1, 0.1, 0.1];
        hAlign = 'left';
        vAlign = 'top';
    otherwise
        label_pos = [ptx-0.05, pty-0.01, 0.1, 0.1];
        hAlign = 'center';
        vAlign = 'bottom';
end
annotation(gcf, 'textbox', ...
        label_pos, ...
        'Color', defaultParams.Color, ...
        'String', str, ...
        'Interpreter', 'latex', ...
        'FontSize', defaultParams.FontSize, ...
        'EdgeColor', 'None', ...
        'FitBoxToText', 'On', ...
        'VerticalAlignment', vAlign, ...
        'HorizontalAlignment', hAlign);
end